#pragma once

#include "ColligereDatabaseItemBase.hpp"

namespace col {

class TreeItemData : public wxTreeItemData { };

//! An abstract base class for a tree control that shows information from a database.
class DatabaseTreeCtrlBase : public wxTreeCtrl
{
public:
	DatabaseTreeCtrlBase();
	virtual ~DatabaseTreeCtrlBase();

	virtual void Initialize() = 0;
	virtual void ClearItemList() = 0;

	void SetBrowseBy ( wxUint32 browseBy );
	wxUint32 GetBrowseBy() const;

	virtual wxTreeItemId AppendItem ( const DatabaseItemBase &rItem, bool select = false ) = 0;
	virtual void SelectItem ( const DatabaseItemBase &rItem, bool select = true ) = 0;
	virtual wxTreeItemId UpdateItem ( const DatabaseItemBase &rItem ) = 0;
	virtual void DeleteItem ( const TreeItemData &rItemData ) = 0;

	virtual void SortCollection ( const wxTreeItemId &rRoot = 0 );

	TreeItemData *GetSelectedItemData();

	class SortChildrenAsc : public std::unary_function < wxTreeItemId, void >
	{
	public:
		SortChildrenAsc ( wxTreeCtrl *pParent ) : mpParent ( pParent ) { }
		void operator() ( wxTreeItemId item ) { 
			if ( mpParent->HasChildren ( item ) )
				mpParent->SortChildren ( item ); 
		}
	private:
		wxTreeCtrl *mpParent;
	};
protected:
	wxTreeItemId FindItem ( wxTreeItemId Root, const wxString &rText );
private:
	wxUint32 mBrowseBy;

//public:
	DECLARE_ABSTRACT_CLASS ( DatabaseTreeCtrlBase );
};

}